package com.ruoyi.system.controller;


import com.alibaba.fastjson.JSONObject;
import com.ruoyi.domain.Shop;
import com.ruoyi.system.service.ShopService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

/**
 * @author 姚炜琦
 * @Classname ShopController
 * @Description TODO
 * @Date 2022/9/14 9:25
 */
@Controller
@RequestMapping("/shop")
@Log4j2
public class ShopController {
    @Autowired
    private ShopService shopService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 商品列表
     * @return
     */
    @RequestMapping("/shopList")
    public String shopList(Model model) {
        log.info("接口功能：【{}】，请求地址：【{}】，请求方式：【{}】，请求参数：【无】",
                "商品列表",request.getRequestURI(),request.getMethod());

        ArrayList<Shop> list = shopService.shopList();
        model.addAttribute("shopList",list);

        log.info("接口功能：【{}】，请求地址：【{}】，请求方式：【{}】，响应结果：【{}】",
                "商品列表",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(list));

        return "list";
    }

    @RequestMapping(value = "/login.html")
    public String login(Model model){
        return "login";
    }

    @RequestMapping(value = "/list.html")
    public String list(Model model){
        return "list";
    }
}
